{extend name="public:base" /}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post" class="ajax-form" action="{:url('product_publicity')}">

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">宣传短视频</label>

                                <div class="col-sm-3"  >
                                    
                                    <img class="upload-file" src="__ADMIN__/img/uploadBtn.png" id="cc">
<!--                                     <div class="video_url">
                                        <a href="{$video}" target='_blank'>点击播放</a>
                                    </div> -->
                                    <video width="320" height="240" controls="controls" class="video_url">
                                        <source src="{$video}" type="video/mp4" />
                                    </video>
                                </div>


                            </div>

                            <div class="hr-line-dashed"></div>
                        </div>


                        <input type="hidden" name="video" id="video" value="{$video}"/>

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="submit" class="btn btn-w-m btn-primary ">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name='js'}

<script>

$("body").on('click','#cc',function(){
    var thisObj = $(this);
    var inputFile = document.createElement("input");
    inputFile.type = "file";
    inputFile.name = "file[]";
    inputFile.multiple = "multiple";
    inputFile.accept = ".mp4";
    inputFile.click();
    $(inputFile).change(function(){
        var files = inputFile.files;
        for(var i=0;i<files.length;i++){
            uploadImg(files[i],thisObj);
        }
    });
});
function uploadImg(file,thisObj){
    var formData = new FormData();
    formData.append('image', file);
    $.ajax({
        url: "{:url('/admin/Manage/uploadImg')}",
        type: "post",
        data: formData,
        dataType:"json",
        contentType: false,
        processData: false,
        mimeType: "multipart/form-data",
        success: function (data) {
            if(data.code == 0){

                alert('成功');
                var img=data.info.imgurl;
                $("input[name='video']").val(img);
                $(".video_url").append("<source src='"+img+"' type='video/mp4' />");


                    var video = document.getElementsByTagName('video')[0];
                    var sources = video.getElementsByTagName('source');
                    sources[0].src =img;
                    sources[1].src =img;
                    video.load();

　　　　　　　}else{
                alert('失败');
            }
        },
    });
}

</script>
{/block}
